package com.ynsj.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ynsj.domain.WebConfig;
import com.ynsj.domain.WorkIssue;
import com.ynsj.model.R;
import com.ynsj.service.WorkIssueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api(tags = "客服工单控制器")
@RequestMapping("/workIssues")
public class WorkIssueController {

    @Autowired
    private WorkIssueService workIssueService;

    @GetMapping
    @ApiOperation("分页查询客服工单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "当前页"),
            @ApiImplicitParam(name = "size",value = "页大小"),
            @ApiImplicitParam(name = "status",value = "工单状态"),
            @ApiImplicitParam(name = "startTime",value = "开始时间"),
            @ApiImplicitParam(name = "endTime",value = "结束时间")
    })
    @PreAuthorize("hasAuthority('work_issue_query')")
    public R<Page<WorkIssue>> findIssuePage(@ApiIgnore Page<WorkIssue> page, Integer status, String startTime, String endTime){
        return R.ok(workIssueService.findByPage(page,status,startTime,endTime));
    }

    @PatchMapping
    @ApiOperation("回复工单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "要回复的工单id"),
            @ApiImplicitParam(name = "status",value = "回复的内容")
    })
    @PreAuthorize("hasAuthority('work_issue_update')")
    public R updateAnswer(Long id, String answer){
        boolean isOk = workIssueService.updateAnswer(id,answer);
        if (isOk){
            return R.ok("回复成功");
        }
        return R.fail("回复失败");
    }
}
